package graphics.primitive;

import java.util.*;

import javax.media.opengl.*;

import graphics.engine.VertexBufferObject;


import utils.*;

public class Cube extends BaseStaticPrimitive 
{

	public static VertexBufferObject vbo = new VertexBufferObject();
	public static int beginMode;
	public Cube(GL gl) {
		super(gl);
		beginMode = GL.GL_TRIANGLES;
	}

	@Override
	public void GenerateVertices(GL gl) 
	{
		if(Cube.vbo.VertexBufferID  != 0)
		{
			return;
		}
		ArrayList<Point3D> vertices = new ArrayList<Point3D>();
		
		vertices.add(new Point3D(-0.5f, -0.5f, 0.5f));	// 0
		vertices.add(new Point3D(0.5f, -0.5f, 0.5f));	// 1	
		vertices.add(new Point3D(-0.5f, 0.5f, 0.5f));	// 2	
		vertices.add(new Point3D(0.5f, 0.5f, 0.5f));  // 3

		vertices.add(new Point3D(-0.5f, -0.5f, -0.5f)); // 4	
		vertices.add(new Point3D(-0.5f, 0.5f, -0.5f));	// 5
		vertices.add(new Point3D(0.5f, -0.5f, -0.5f));	// 6	
		vertices.add(new Point3D(0.5f, 0.5f, -0.5f)); // 7
		
		vertices.add(new Point3D(-0.5f, 0.5f, 0.5f)); // 8
		vertices.add(new Point3D(-0.5f, 0.5f, -0.5f));	//9
		vertices.add(new Point3D(-0.5f, -0.5f, 0.5f));	//10	
		vertices.add(new Point3D(-0.5f, -0.5f, -0.5f)); // 11

		vertices.add(new Point3D(0.5f, 0.5f, -0.5f));	// 12
		vertices.add(new Point3D(0.5f, 0.5f, 0.5f));	// 13
		vertices.add(new Point3D(0.5f, -0.5f, 0.5f)); // 14
		vertices.add(new Point3D(0.5f, -0.5f, -0.5f));	//15
		
		vertices.add(new Point3D(-0.5f, -0.5f, -0.5f)); // 16
		vertices.add(new Point3D(0.5f, -0.5f, -0.5f));	// 17
		vertices.add(new Point3D(-0.5f, -0.5f, 0.5f)); // 18
		vertices.add(new Point3D(0.5f, -0.5f, 0.5f)); // 19

		vertices.add(new Point3D(0.5f, 0.5f, -0.5f));	// 20
		vertices.add(new Point3D(-0.5f, 0.5f, 0.5f));	// 21
		vertices.add(new Point3D(0.5f, 0.5f, 0.5f)); //22
		vertices.add(new Point3D(-0.5f, 0.5f, -0.5f));	 //23
		
		Cube.vbo.GenerateVertexBuffer(gl, vertices);		
	}

	@Override
	public void GenerateIndices(GL gl) {
		if(Cube.vbo.IndexBufferID != 0)
		{
			return;
		}
		short[] indices = new short[]
		{
			0,1,2,
			1,3,2,
			4,5,6,
			6,5,7,
			8,9,10,
			9,11,10,
			12,13,14,
			15,12,14,
			16,17,18,
			17,19,18,
			20,21,22,
			23,21,20
		};	
		
		Cube.vbo.GenerateIndexBuffer(gl, indices);
	}
}
